home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / term / ncomm306.lha / chippatch / src / NCommToChipPatch.c < prev    next >
C/C++ Source or Header  |  1996-02-19  |  3KB  |  119 lines

  1. /* NCommToChipPatch.c
  2.  
  3.     Auto: SC LINK NOSTKCHK NOSTARTUP <path>NCommToChipPatch.c OBJ <path>sprintf.o
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <libraries/dos.h>
  8. #include <proto/exec.h>
  9. #include <proto/dos.h>
  10. #include <string.h>
  11.  
  12. #define BUFFERSIZE 400*1024
  13.  
  14. extern APTR SPrintf(STRPTR dest, STRPTR fmtstr, ...);
  15.  
  16. UBYTE *template = "NCOMMEXECUTABLE,USAGE/S";
  17. enum {
  18.    TEM_NCOMMEXECUTABLE,
  19.    TEM_USAGE,
  20.    TEM_NUMBEROF
  21. };
  22.  
  23. UBYTE __far buffer[BUFFERSIZE];
  24. UBYTE toname[250];
  25.  
  26. STRPTR fmtstr =
  27. "NCommToChipPatch V1.1  Usage: NCommToChipPatch [ncommexecutable]\n"
  28. "Copyright © 1996 Ultima Thule Software. Author: Eivind Nordseth.\n"
  29. "This program will create a patched NComm which makes all hunks\n"
  30. "to end up in chip memory when loaded. This will slow NComm down,\n"
  31. "and make it usable on Faaaaaaaaaaaaaaaaaast Amigas. No more hickups.\n"
  32. "The patched file will be saved as ChipNComm in the same directory as\n"
  33. "the ncomm executable. 3.02k, 3.05 and 3.06 versions can be patched.\n%s";
  34.  
  35. LONG __saveds NoName(void)
  36. {
  37.    struct DosLibrary *DOSBase;
  38.    struct RDArgs *rdargs = NULL, *args = NULL;
  39.    LONG array[TEM_NUMBEROF], retval = RETURN_ERROR, read;
  40.    STRPTR ptr;
  41.    BPTR fh = NULL;
  42.  
  43.    if(!(DOSBase = (struct DosLibrary *) OpenLibrary(DOSNAME, 37L))) 
  44.       return(10000L);
  45.  
  46.    if(!(args = AllocDosObject(DOS_RDARGS, NULL))) goto quit;
  47.    setmem(array, TEM_NUMBEROF * sizeof(LONG), 0);
  48.  
  49.    SPrintf(args->RDA_ExtHelp = buffer, fmtstr, template);
  50.       
  51.    if(!(rdargs = ReadArgs(template, array, args)))
  52.    {
  53.       Printf("Error in arguments.");
  54.       goto quit;
  55.    }
  56.  
  57.    if(array[TEM_USAGE] || !array[TEM_NCOMMEXECUTABLE])
  58.    {
  59.       Printf(fmtstr, "");
  60.       retval = RETURN_OK;
  61.       goto quit;
  62.    }
  63.  
  64.     if(!(fh = Open((STRPTR) array[TEM_NCOMMEXECUTABLE], MODE_OLDFILE))) 
  65.     {
  66.         Printf("Could not open %s\n", array[TEM_NCOMMEXECUTABLE]);
  67.         goto quit;
  68.     }
  69.     
  70.     read = Read(fh, buffer, BUFFERSIZE);
  71.     
  72.     if(read == 216292) Printf("NComm 3.02k version found.\n");
  73.     else if(read == 218244) Printf("NComm 3.05 version found.\n");
  74.     else if(read == 222928) Printf("NComm 3.06 version found.\n");
  75.     else
  76.     {
  77.         Printf("%s is no known NComm version\n", array[TEM_NCOMMEXECUTABLE]);
  78.         goto quit;
  79.     }
  80.  
  81.     buffer[0x14] = 0x40;
  82.     buffer[0x1C] = 0x40;
  83.  
  84.     buffer[0x20] = 0x40;
  85.     buffer[0x24] = 0x40;
  86.     buffer[0x28] = 0x40;
  87.     
  88.     
  89.     strcpy(toname, (STRPTR) array[TEM_NCOMMEXECUTABLE]);
  90.     ptr = PathPart(toname);
  91.     if(*ptr == '/') *ptr++;
  92.     strcpy(ptr, "ChipNComm");
  93.     
  94.     Close(fh);
  95.     if(!(fh = Open(toname, MODE_NEWFILE)))
  96.     {
  97.         Printf("Could not create ChipNComm\n");
  98.         goto quit;
  99.     }
  100.  
  101.     if(Write(fh, buffer, read) != read)
  102.     {
  103.         Printf("Failed to write output file\n");
  104.         goto quit;
  105.     }
  106.  
  107.     Printf("A patched version of NComm is now saved as %s.\n", toname);
  108.  
  109.    retval = RETURN_OK;
  110.  
  111. quit:
  112.     if(fh) Close(fh);
  113.    if(rdargs) FreeArgs(rdargs);
  114.    if(args) FreeDosObject(DOS_RDARGS, args);
  115.  
  116.    CloseLibrary((struct Library *) DOSBase);
  117.    return(retval);
  118. }
  119.